package com.sanjin.service.impl;

        import com.sanjin.entity.Admin;
        import com.sanjin.repository.AdminRepository;
        import com.sanjin.service.AdminService;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.security.core.userdetails.UserDetails;
        import org.springframework.security.core.userdetails.UserDetailsService;
        import org.springframework.security.core.userdetails.UsernameNotFoundException;
        import org.springframework.stereotype.Service;
        import org.springframework.transaction.annotation.Propagation;
        import org.springframework.transaction.annotation.Transactional;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/5/5 16:34
 */
@Service
public class AdminDetailsService implements UserDetailsService {

    @Autowired
    private AdminRepository adminRepository;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Admin admin = adminRepository.findByUsername(username);
        if (admin == null)
            throw new UsernameNotFoundException("用户名不存在: " + username);
        return admin;
    }
}
